﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormApp {
    public partial class Form2 : Form {
        public Form2() {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) {
            entityDataSource1.ObjectContext.ContextOptions.LazyLoadingEnabled = false;
            var category = ((NORTHWNDEntities)entityDataSource1.ObjectContext).Categories.First();
            category.Products.Load();
            //categoryBindingSource.CurrencyManager.Refresh();
            categoryBindingSource.Add(category);


            //var curr = this.BindingContext[categoryBindingSource.DataSource, categoryBindingSource.DataMember] as CurrencyManager;
            //curr.List.Add(category);

            //rootSource.CurrencyManager.List.Add(entity);
            //if (this.CurrencyManager != null && this.CurrencyManager.List is IBindingList && _rootEntity != null) {
            //    var bl = rootSource.CurrencyManager.List as IBindingList;
            //    rootSource.CurrencyManager.Position = bl.IndexOf(_rootEntity);
            //}
        }

        private void button2_Click(object sender, EventArgs e) {
            var cm = this.BindingContext[entityDataSource1, "Products"] as CurrencyManager;
            cm.List.Remove(dataGridView2.CurrentRow.DataBoundItem);
            
            //var lst = entityDataSource1.EntitySets["Products"].List;
            //lst.Remove(dataGridView2.CurrentRow.DataBoundItem);

            //entityDataSource1.EntitySets["Categories"].RefreshView();
        }

        private void button3_Click(object sender, EventArgs e) {
            var v = categoryBindingSource.Current;
        }
    }
}
